<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }

        .self-form-item {
            margin-left: 70px;
        }

        .self-input {
            height: auto;
            padding: 5px;
            line-height: 38px;
            border-width: 1px;
            border-style: solid;
            background-color: #fff;
            border-radius: 2px;
            border-color: #eee;
        }

        .self-tag {
            background-color: #ecf5ff;
            display: inline-block;
            height: 32px;
            padding: 0 10px;
            line-height: 30px;
            font-size: 12px;
            user-select: none;
            color: #409eff;
            border: 1px solid #d9ecff;
            border-radius: 4px;
            box-sizing: border-box;
            white-space: nowrap;
            margin-right: 5px;
        }

        .close-icon::before {
            content: "x";
        }

        .self-tag>i::before {
            border-radius: 50%;
            text-align: center;
            position: relative;
            cursor: pointer;
            font-size: 12px;
            height: 16px;
            width: 16px;
            line-height: 16px;
            vertical-align: middle;
            top: -1px;
            right: -5px;
            font-family: element-icons !important;
            speak: none;
            font-style: normal;
            font-weight: 400;
            font-variant: normal;
            text-transform: none;
            line-height: 1;
            vertical-align: baseline;
            display: inline-block;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .self-tag>i:hover::before {
            color: #fff;
            background-color: #409eff;
        }
    </style>
</head>

<body>

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">试卷标题</label>
            <div class="layui-input-block">
                <input type="text" name="t" lay-verify="required" lay-reqtext="题目标题不能为空" placeholder="请输入题目标题" value=""
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">考试限时</label>
            <div class="layui-input-block">
                <input type="number" name="m" lay-verify="required" lay-reqtext="限时不能为空" placeholder="请输入考试限时，单位（分钟）"
                    min="1" max="360" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">选择题目</label>
            <div class="layui-input-block self-input" id="q_ids">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>

    <fieldset class="table-search-fieldset self-form-item">
        <legend>搜索信息</legend>
        <div style="margin: 10px 10px 10px 10px">
            <form class="layui-form layui-form-pane" lay-filter="table-search" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">题目名字</label>
                        <div class="layui-input-inline">
                            <input type="text" name="question" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">题目类型</label>
                        <div class="layui-input-inline">
                            <select name="type" autocomplete="off">
                                <option value=""></option>
                                <option value="radio">单选</option>
                                <option value="checkbox">多选</option>
                                <option value="judge">是非</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">创建人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" id="search" class="layui-btn layui-btn-primary" lay-submit
                            lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加</button>
        </div>
      </script>

    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="add">添加</a>
      </script>

    <div class="self-form-item">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
    
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            $.get('../../action.php', { a: 'quesg', id: getQueryVariable('id') }, function (result, status, xhr) {
                if (result.success) {
                    const data = result.data;
                    form.val('editForm', {
                        id: data.id,
                        t: data.question,
                        type: data.type,
                        ans: data.answer,
                        a: data.A,
                        b: data.B,
                        c: data.C,
                        d: data.D,
                    })
                    form.render();
                }
            });


            function getQueryVariable(variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) { return pair[1]; }
                }
                return (false);
            }

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.post("../../action.php?a=quesu", JSON.parse(JSON.stringify(data.field)), (data, status) => {
                    if (data.success) {
                        layer.msg("修改成功", { time: 0 });

                        setTimeout(() => {
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 2000);
                    } else {
                        layer.alert(data.message)
                    }
                })
                return false;
            });

        });
    </script>
</body>

</html>